#include <mqueue.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>


int main(){
    mqd_t mq=mq_open("/mq",O_CREAT | O_WRONLY,0666,NULL);
    if(mq==(mqd_t)-1){
        perror("mq_open error");
        exit(1);
    }
    char buffer[1024];

    while(1){
        memset(buffer,0,sizeof(buffer));
        printf("Enter message:");
        fflush(stdout);
        fgets(buffer,sizeof(buffer)-1,stdin);
        ssize_t len=mq_send(mq,buffer,sizeof(buffer),3);
        if(len<0){
            perror("mq_send error");
            exit(2);
        }
        if(strncmp(buffer,"quit",4)==0){
            break;
        }
        printf("send message:%s",buffer);
        fflush(stdout);
    }
    return 0;
}